package cn.buk.tms.entity.misc;

import cn.buk.common.util.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.util.Date;
import jakarta.persistence.Basic;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;

/**
 * Pnr类中删除的，这里也保留一份，作为历史备份
 */
@Entity
@Table(name = "t240_used")
public class PnrUsed {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;

  @Column(name = "enterprise_id", nullable = false)
  private int enterpriseId;

  /**
   * 在Pnr(t240)中的id
   */
  @Column(name = "old_id")
  private int oldId;

  @Column(length = 7, nullable = false, name = "pnr_no")
  private String pnrNo;

  /**
   * 大编码，和pnrno配合，确定是否为同一个编码
   */
  @Column(length = 7, name = "big_pnr")
  private String bigPnrNo;

  /**
   * 第一程或单程的出发机场
   */
  @Column(name = "dport", length = 3)
  private String dport;

  /**
   * 第一程或单程的到达机场
   */
  @Column(name = "aport", length = 3)
  private String aport;

  /**
   * 第一程或单程的航班号
   */
  @Column(name = "flight_no", length = 7)
  private String flightNo;

  /**
   * 第一程或单程的出发日期
   */
  @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  @Temporal(TemporalType.DATE)
  @Column(name = "ddate")
  private Date ddate;

  /**
   * 第一程或单程的出发时间
   */
  @Column(name = "dtime", length = 4)
  private String dtime;

  /**
   * 第一程或单程的预定的舱位
   */
  @Column(length = 2, name = "sub_class")
  private String subClass;


  @Column(name = "customer_id")
  private Integer customerId;

  /**
   * 预定该PNR的用户所使用的eterm用户名
   */
  @Column(length = 32, name = "eterm_username")
  private String etermUsername;

  /**
   * 出票时限
   */
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "dz_time")
  private Date dzTime;

  /**
   * 出票状态
   * 0-未出票
   * 1-已出票
   */
  @Column(name = "dz_status")
  private Integer dzStatus = 0;

  /**
   * 出票日期
   * 从t233中找到对应的编码，并将他的出票日期写入进来
   */
  @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  @Temporal(TemporalType.DATE)
  @Column(name = "etdz_date")
  private Date etdzDate;

  /**
   * 出票的office
   */
  @Column(length = 6, name = "etdz_office")
  private String etdzOffice;

  /**
   * 0 - 此编码正常状态
   * 1 - 此编码已取消
   * 4 - NO PNR
   */
  @Column(length = 1, name = "xe_status")
  private Integer xeStatus = 0;

  /**
   * 航段状态
   * --用于显示PNR中需要提醒业务员注意的航段，比如HX,NO等航段
   */
  @Column(length = 10, name = "seg_status")
  private String segStatus;

  /**
   * 编码的处理状态
   * 0-不需要处理
   * 1-需要处理，取出pnrDetail，重新分析出票时限
   * 2-需要处理，取出pnrDetail, 重新分析pnrNo
   */
  private int status;

  private int price;

  private int tax;

  @Column(name = "seg_count")
  private int segCount;

  /**
   * passenger count
   */
  @Column(name = "psg_count")
  private int psgCount;

  @Column(name = "ticket_count")
  private int ticketCount;

  /**
   * pnr中包含的ctcm数量
   */
  @Column(name = "ctcm_count")
  private Integer ctcmCount;

  @Lob
  @Basic(fetch = FetchType.LAZY)
  @Column(name = "pnr_detail")
  private String pnrDetail;

  @Column(length = 2000)
  private String remark;

  /**
   * PNR的清Q日期
   */
  @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  @Temporal(TemporalType.DATE)
  @Column(insertable = false, name = "issue_date")
  private Date issueDate;

  /**
   * 该记录保存到数据库的时间, PNR创建时间，仅供参考
   */
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "create_time")
  private Date createTime;

  /**
   * 最后更新时间
   */
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  @Temporal(TemporalType.TIMESTAMP)
  @Column(insertable = false, updatable = false, name = "lastupdate")
  private Date lastUpdate;

  /**
   * 冗余字段,保存最大的航班起飞日期
   */
  @Temporal(TemporalType.DATE)
  @Column(name = "max_departure_date")
  private Date maxDepartureDate;

  /**
   * 冗余字段,保存最小的航班起飞日期
   */
  @Temporal(TemporalType.DATE)
  @Column(name = "min_departure_date")
  private Date minDepartureDate;

  @Column(length = 20, name = "link_phone")
  private String linkphone;

  /**
   * 预订office
   */
  @Column(name = "sd_office", length = 6)
  private String bookOfficeNo;


  public String getUpdateTimeDesc() {
    if (lastUpdate == null) {
      return "";
    } else {
      return DateUtil.getUpdateTimeDesc(lastUpdate);
    }
  }


  /**
   * @return the id
   */
  public int getId() {
    return id;
  }

  /**
   * @param id the id to set
   */
  public void setId(int id) {
    this.id = id;
  }

  /**
   * @return the dzTime
   */
  public Date getDzTime() {
    return dzTime;
  }

  /**
   * @param dzTime the dzTime to set
   */
  public void setDzTime(Date dzTime) {
    this.dzTime = dzTime;
  }

  /**
   * @return the price
   */
  public double getPrice() {
    return price;
  }

  /**
   * @param price the price to set
   */
  public void setPrice(int price) {
    this.price = price;
  }

  /**
   * @return the tax
   */
  public double getTax() {
    return tax;
  }

  /**
   * @param tax the tax to set
   */
  public void setTax(int tax) {
    this.tax = tax;
  }

  /**
   * @return the segCount
   */
  public int getSegCount() {
    return segCount;
  }

  /**
   * @param segCount the segCount to set
   */
  public void setSegCount(int segCount) {
    this.segCount = segCount;
  }

  /**
   * @return the psgCount
   */
  public int getPsgCount() {
    return psgCount;
  }

  /**
   * @param psgCount the psgCount to set
   */
  public void setPsgCount(int psgCount) {
    this.psgCount = psgCount;
  }

  /**
   * @return the pnrDetail
   */
  public String getPnrDetail() {
    return pnrDetail == null ? "" : pnrDetail;
  }

  /**
   * @param pnrDetail the pnrDetail to set
   */
  public void setPnrDetail(String pnrDetail) {
    this.pnrDetail = pnrDetail;
  }


  /**
   * @return the pnrNo
   */
  public String getPnrNo() {
    return this.pnrNo == null ? "" : this.pnrNo.trim();
  }

  /**
   * @param pnrNo the pnrNo to set
   */
  public void setPnrNo(String pnrNo) {
    if (pnrNo != null) {
      pnrNo = pnrNo.trim();
    }
    this.pnrNo = pnrNo;
  }

  public int getTicketCount() {
    return this.ticketCount;
  }

  public void setTicketCount(int ticketCount) {
    this.ticketCount = ticketCount;
  }


  public Date getIssueDate() {
    return issueDate;
  }

  public void setIssueDate(Date issueDate) {
    this.issueDate = issueDate;
  }

  /**
   * @return the remark
   */
  public String getRemark() {
    return remark;
  }

  /**
   * @param remark the remark to set
   */
  public void setRemark(String remark) {
    this.remark = remark;
  }

  /**
   * @return the customer
   */
  public Integer getCustomer() {
    return customerId;
  }

  /**
   * @param customer the customer to set
   */
  public void setCustomer(Integer customer) {
    this.customerId = customer;
  }

  /**
   * @return the enterpriseId
   */
  public int getEnterpriseId() {
    return enterpriseId;
  }

  /**
   * @param enterpriseId the enterpriseId to set
   */
  public void setEnterpriseId(int enterpriseId) {
    this.enterpriseId = enterpriseId;
  }

  public Integer getDzStatus() {

    return dzStatus;
  }

  public void setDzStatus(Integer dzStatus) {
    this.dzStatus = dzStatus;
  }

  public String getSegStatus() {
    return segStatus;
  }

  public void setSegStatus(String segStatus) {
    this.segStatus = segStatus;
  }

  public Date getLastUpdate() {
    return lastUpdate;
  }

  public void setLastUpdate(Date lastUpdate) {
    this.lastUpdate = lastUpdate;
  }

  public String getEtermUsername() {
    if (this.etermUsername == null) {
      return "";
    } else {
      return etermUsername;
    }
  }

  public void setEtermUsername(String etermUsername) {
    this.etermUsername = etermUsername;
  }

  public Date getEtdzDate() {
    return etdzDate;
  }

  public void setEtdzDate(Date etdzDate) {
    this.etdzDate = etdzDate;
  }

  public String getEtdzOffice() {
    return etdzOffice;
  }

  public void setEtdzOffice(String etdzOffice) {
    this.etdzOffice = etdzOffice;
  }

  public Integer getXeStatus() {
    if (this.xeStatus == null) {
      this.xeStatus = 0;
    }
    return xeStatus;
  }

  public void setXeStatus(Integer xeStatus) {
    this.xeStatus = xeStatus;
  }

  public int getIntXeStatus() {
    if (this.xeStatus == null) {
      return 0;
    } else {
      return this.xeStatus;
    }
  }

  public int getIntDzStatus() {
    if (this.dzStatus == null) {
      return 0;
    } else {
      return dzStatus;
    }
  }

  public Date getMinDepartureDate() {
    return minDepartureDate;
  }

  public void setMinDepartureDate(Date minDepartureDate) {
    this.minDepartureDate = minDepartureDate;
  }

  public Date getMaxDepartureDate() {
    return maxDepartureDate;
  }

  public void setMaxDepartureDate(Date maxDepartureDate) {
    this.maxDepartureDate = maxDepartureDate;
  }

  public int getStatus() {
    return status;
  }

  public void setStatus(int status) {
    this.status = status;
  }

  public String getDport() {
    return dport;
  }

  public void setDport(String departurePort) {
    this.dport = departurePort;
  }

  public String getAport() {
    return aport;
  }

  public void setAport(String arrivalPort) {
    this.aport = arrivalPort;
  }

  public String getFlightNo() {
    return flightNo;
  }

  public void setFlightNo(String flightNo) {
    this.flightNo = flightNo;
  }

  public Date getDdate() {
    return ddate;
  }

  public void setDdate(Date departureDate) {
    this.ddate = departureDate;
  }

  public String getSubClass() {
    return subClass;
  }

  public void setSubClass(String subClass) {
    this.subClass = subClass;
  }

  public String getDtime() {
    return dtime;
  }

  public void setDtime(String departureTime) {
    this.dtime = departureTime;
  }

  public String getCarrier() {
    if (flightNo == null) {
      return "";
    } else {
      return flightNo.substring(0, 2);
    }

  }

  public String getLinkphone() {
    if (this.linkphone == null) {
      return "";
    } else {
      return linkphone.trim();
    }
  }

  public void setLinkphone(String linkphone) {
    if (linkphone == null) {
      linkphone = "";
    } else if (linkphone.length() > 20) {
      linkphone = linkphone.substring(0, 20);
    }

    this.linkphone = linkphone;
  }

  public String getBookOfficeNo() {
    if (bookOfficeNo == null) {
      return "";
    } else {
      return bookOfficeNo;
    }
  }

  public Integer getOldId() {
    return oldId;
  }

  public void setOldId(Integer oldId) {
    this.oldId = oldId;
  }

  public String getBigPnrNo() {
    return this.bigPnrNo == null ? "" : bigPnrNo;
  }

  public void setBigPnrNo(String bigPnrNo) {
    this.bigPnrNo = bigPnrNo;
  }

  public int getCtcmCount() {
    return ctcmCount == null ? 0 : ctcmCount;
  }

  public void setCtcmCount(Integer ctcmCount) {
    this.ctcmCount = ctcmCount;
  }

  public void setBookOfficeNo(String bookOfficeNo) {
    this.bookOfficeNo = bookOfficeNo;
  }

  public Date getCreateTime() {
    return createTime;
  }

  public void setCreateTime(Date createTime) {
    this.createTime = createTime;
  }
}
